<?php
set_time_limit(0);
$dbhost = '47.110.131.55';
$dbuser = 'root';
$dbpwd  ='sxy7788123456';
$dbName ='race';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
$nianji=1;
$step=2;
$query=$mysqli->query("select id,step,title,da,db,dc,dd,dan from ti where nianji='".$nianji."' and step=".$step." order by tid ");
$tiAInfo=array();
while ($list=$query->fetch_array()){
    $tiAInfo[]=array('id'=>$list['id'],'title'=>$list['title'],'da'=>$list['da'],'db'=>$list['db']
        ,'dc'=>$list['dc'],'dd'=>$list['dd']
    );
}

for ($j=1;$j<8;$j++){
    shuffle($tiAInfo);
    $tiBInfo=array();
    foreach ($tiAInfo as $list){
            $tiBInfo[]=array('id'=>$list['id'],'title'=>$list['title'],'da'=>$list['da'],'db'=>$list['db']
                ,'dc'=>$list['dc'],'dd'=>$list['dd']);
    }
    file_put_contents('../tiKu/'.$nianji.'-'.$step.'-'.$j.'.txt', json_encode(array('a'=>$tiBInfo)));
    
}
echo $nianji;

$mysqli->close();